﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using BitcoinMarket.Resources;
using Microsoft.Phone.Shell;
using BitcoinMarket.Libs;

namespace BitcoinMarket.ViewModels
{
    public partial class AboutPage : PhoneApplicationPage
    {
        public AboutPage()
        {
            InitializeComponent();
        }

        private void HyperlinkButton_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            WebBrowserTask wbTask = new WebBrowserTask();
            string url = "http://blockchain.info";
            wbTask.Uri = new Uri(url, UriKind.RelativeOrAbsolute);
            wbTask.Show();
        }

        private void HyperlinkButton_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            WebBrowserTask wbTask = new WebBrowserTask();
            string url = "http://bitcoincharts.com";
            wbTask.Uri = new Uri(url, UriKind.RelativeOrAbsolute);
            wbTask.Show();
        }

        private void HyperlinkButton_Tap_2(object sender, System.Windows.Input.GestureEventArgs e)
        {
            WebBrowserTask wbTask = new WebBrowserTask();
            string url = "http://www.quandl.com";
            wbTask.Uri = new Uri(url, UriKind.RelativeOrAbsolute);
            wbTask.Show();
        }

        private void Button_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();

            marketplaceReviewTask.Show();
        }

        private void Button_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            EmailComposeTask emailComposeTask = new EmailComposeTask();

            emailComposeTask.Subject = AppResources.feedbackEmailSubject + " [" + AppResources.appVersion + "]";
            emailComposeTask.Body = "";
            emailComposeTask.To = AppResources.FeedbackEmail;

            emailComposeTask.Show();
        }

        private void ApplicationBarMenuItem_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/AppSettingsPage.xaml", UriKind.Relative));
        }

        private void Button_Tap_2(object sender, System.Windows.Input.GestureEventArgs e)
        {
            EmailComposeTask emailComposeTask = new EmailComposeTask();

            emailComposeTask.Subject = AppResources.DonationEmailSubject;
            emailComposeTask.Body = AppResources.DonationEmailBody.Replace("%s", AppResources.WalletAddr);
            emailComposeTask.To = "";

            emailComposeTask.Show();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            SystemTray.IsVisible = true;
            SystemTray.Opacity = 0;
            SystemTray.ForegroundColor = Colors.White;

            this.BuildLocalizedApplicationBar();
        }

        /**
         * Builds the application Bar with translations
         */
        private void BuildLocalizedApplicationBar()
        {
            ApplicationBar = new ApplicationBar();
            ApplicationBar.ForegroundColor = Colors.Black;
            ApplicationBar.BackgroundColor = ColorTools.GetColorFromHexa("#FFD8D8D8");
            ApplicationBar.Mode = ApplicationBarMode.Minimized;

            ApplicationBarMenuItem appBarItemSettings = new ApplicationBarMenuItem(AppResources.SettingMenuItem);
            appBarItemSettings.Click += this.ApplicationBarMenuItem_Click;
            ApplicationBar.MenuItems.Add(appBarItemSettings);
        }
    }
}